<?php
namespace tp5_lib\mail\logic;

class Examine
{
    /**
     * 检查CA证书设置
     * @see https://www.cnblogs.com/zjhblogs/p/5891885.html
     */
    static public function checkCAFile()
    {
        set_error_handler(function($errno,$errstr,$errfile,$errline){
            return true;
        });

        $fp = fopen('http://www.baidu.com', 'r', false);
        if($fp === false) return "网络不通，或者百度挂了";
        else fclose($fp);

        $fp = fopen('https://www.baidu.com', 'r', false);
        if($fp === false) return "OS/PHP的CA证书需要更新，或者百度的SSL证书有问题\r\n  更新CA证书@see https://www.cnblogs.com/zjhblogs/p/5891885.html";
        else fclose($fp);

        return true;
    }
    /**
     * 检查相关PHP扩展
     */
    static public function checkExtension()
    {
        $sockets=extension_loaded("sockets");
        $openssl=extension_loaded("openssl");
        if(!$sockets){
            if(!$openssl) return "需要安装sockets,openssl扩展";
            else return "需要安装sockets扩展";
        }
        else{
            if(!$openssl) return "需要安装openssl扩展";
        }
        return true;
    }
}
